package com.sky.controller.admin;

import com.sky.dto.SetmealDTO;
import com.sky.dto.SetmealPageQueryDTO;
import com.sky.result.Result;
import com.sky.service.SetmealService;
import com.sky.vo.PageResult;
import com.sky.vo.SetmealVO;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.cache.annotation.CacheEvict;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.List;

/**
 * PROJECT_NAME: sky-take-out
 * NAME: SetmealController
 *
 * @AUTHOR: zhang
 * DATE: 2023/11/24
 * DESCRIPTION :
 */
@Slf4j
@Api(tags = "B端-套餐信息表现层接口") //@Api:用户描述类的相关信息
@RestController
@RequestMapping("/admin/setmeal")
public class SetmealController {

    @Resource
    private SetmealService setmealService;

    @ApiOperation("套餐分页查询")
    @GetMapping("/page")
    public Result<PageResult> getPage(SetmealPageQueryDTO pageQueryDTO){
        return setmealService.getPage(pageQueryDTO);
    }

    @PostMapping
    @ApiOperation("新增套餐")
    ////删除所有前缀是SETMEAL_CACHE的缓存数据
    @CacheEvict(value = "SETMEAL_CACHE",allEntries = true)
    public Result insertSetmeal(@RequestBody SetmealDTO setmealDTO){
        log.info("【新增套餐】");
        setmealService.insertSetmeal(setmealDTO);
        return Result.success();
    }

    @ApiOperation("删除套餐")
    @DeleteMapping
    public Result deleteSetmeal(@RequestParam List<Long> ids){
        log.info("【删除套餐】");
        setmealService.deleteSetmeal(ids);
        return Result.success();
    }

    @ApiOperation("根据id查询套餐")
    @GetMapping("/{id}")
    public Result<SetmealVO> selectSetmealById(@PathVariable Long id){
        SetmealVO setmealVO = setmealService.getSetmealById(id);
        return Result.success(setmealVO);
    }

    @ApiOperation("修改套餐")
    @PutMapping
    public Result updateSetmeal(@RequestBody SetmealDTO setmealDTO){
        setmealService.updateSetmeal(setmealDTO);
        return  Result.success();
    }

    @ApiOperation("修改套餐状态")
    @PostMapping("/status/{status}")
    public Result updateSetmealStatus(@PathVariable Integer status,Long id){
        setmealService.updateSetmealStatus(status,id);
        return Result.success();
    }
}
